package com.hzj.recipe.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.hzj.recipe.entity.Admin;
import com.hzj.recipe.entity.User;
import com.hzj.recipe.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * 注册接口
 *
 * @author makejava
 * @since 2024-01-04 11:25:28
 */
@RestController
@RequestMapping("/register")
public class RegisterController {
    @Autowired
    private LoginService loginService;

    /**
     * 用户注册
     *
     * @param user 注册实体
     * @return 注册结果
     */
    @PostMapping("register")
    public R register(@RequestBody User user){
        user.setCreateTime(LocalDateTime.now());
        return loginService.register(user);
    }

    /**
     * 管理员注册
     *
     * @param admin 注册实体
     * @return 注册结果
     */
    @PostMapping("adminRegister")
    public R adminRegister(@RequestBody Admin admin){
        admin.setCreateTime(LocalDateTime.now());
        return loginService.adminRegister(admin);
    }
}
